package com.gobang.common.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ配置类
 */
@Configuration
public class RabbitMQConfig {

    /**
     * 测试队列名称
     */
    public static final String TEST_QUEUE = "gobang.test.queue";

    /**
     * 游戏结果事件队列
     */
    public static final String GAME_RESULT_QUEUE = "gobang.game.result.queue";

    /**
     * 用户注册事件队列
     */
    public static final String USER_REGISTER_QUEUE = "gobang.user.register.queue";

    /**
     * 创建测试队列
     */
    @Bean
    public Queue testQueue() {
        // durable=true：队列持久化
        return new Queue(TEST_QUEUE, true);
    }

    /**
     * 创建游戏结果事件队列
     */
    @Bean
    public Queue gameResultQueue() {
        return new Queue(GAME_RESULT_QUEUE, true);
    }

    /**
     * 创建用户注册事件队列
     */
    @Bean
    public Queue userRegisterQueue() {
        return new Queue(USER_REGISTER_QUEUE, true);
    }

    @Bean
    public MessageConverter messageConverter(ObjectMapper objectMapper) {
        return new Jackson2JsonMessageConverter(objectMapper);
    }
}

